<template>
  <div>

    <el-tabs :tab-position="tabPosition" @tab-click="changeTab" v-model="activeName">
      <el-tab-pane label="企业基础材料" name="tab1">

        <el-table :data="tableData" border style="width: 100%" size="mini">
          <el-table-column type="index" label="序号" align="center" width="50">
          </el-table-column>
          <el-table-column prop="mateName" label="资料名称" align="center" width="230">
          </el-table-column>
          <el-table-column prop="isMust" label="是否必备" align="center" :formatter="isMustFor">
          </el-table-column>
          <el-table-column prop="isFormerly" label="是否原件" align="center" :formatter="isFormerlyFor">
          </el-table-column>
          <el-table-column prop="isProvide" label="是否提供" align="center">
            <template slot-scope="scope">
              <el-checkbox v-model="scope.row.isProvide" @change="checkedIsUse(scope.row)"></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column prop="checkUserName" label="确认人" align="center">
          </el-table-column>
          <el-table-column prop="checkDate" label="确认时间" align="center" :formatter="createTimeFor">
          </el-table-column>
          <el-table-column prop="uploDocNum" label="上传文档数" align="center">
          </el-table-column>
          <el-table-column label="操作" align="center" width="100">
            <template slot-scope="scope">
              <el-button @click="handleClick(scope.row)" type="text" size="small">上传</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="反担保材料" name="tab2">
        <el-table :data="tableData2" border style="width: 100%" size="mini">
          <el-table-column type="index" label="序号" align="center" width="50">
          </el-table-column>
          <el-table-column prop="mateName" label="资料名称" align="center" width="230">
          </el-table-column>
          <el-table-column prop="isMust" label="是否必备" align="center" :formatter="isMustFor">
          </el-table-column>
          <el-table-column prop="isFormerly" label="是否原件" align="center" :formatter="isFormerlyFor">
          </el-table-column>
          <el-table-column prop="isProvide" label="是否提供" align="center">
            <template slot-scope="scope">
              <el-checkbox v-model="scope.row.isProvide" @change="checkedIsUse(scope.row)"></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column prop="checkUserName" label="确认人" align="center">
          </el-table-column>
          <el-table-column prop="checkDate" label="确认时间" align="center" :formatter="createTimeFor">
          </el-table-column>
          <el-table-column prop="uploDocNum" label="上传文档数" align="center">
          </el-table-column>
          <el-table-column label="操作" align="center" width="100">
            <template slot-scope="scope">
              <el-button @click="handleClick(scope.row)" type="text" size="small">上传</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <el-dialog title="附件选择" :visible.sync="dialogTableVisible" @close="quXiao">
      <projMateUploadQyComponent :formData.sync="formData" ref="projMateUploadQyComponent"></projMateUploadQyComponent>
    </el-dialog>

    <el-dialog title="附件选择" :visible.sync="dialogTableVisible1" @close="quXiao1">
      <projMateUploadFdbComponent :formData.sync="formData" ref="projMateUploadFdbComponent"></projMateUploadFdbComponent>
    </el-dialog>
  </div>
</template>

<script>
export default {
  components: {
    projMateUploadQyComponent: require("@/pages/biz/proj/proj-mate-upload-qy.vue")
      .default,
    projMateUploadFdbComponent: require("@/pages/biz/proj/proj-mate-upload-fdb.vue")
      .default
  },
  //props: ["projId"],
  data() {
    return {
      activeName: "tab1",
      formData: { id: "", projId: "", uploDocNum: "" },
      tabPosition: "right",
      tableData: [],
      dialogTableVisible: false,
      proId: "",
      dialogTableVisible1: false,
      mateType: 1,
      tableData2: []
    };
  },
  mounted() {},
  methods: {
    createTimeFor(row, column) {
      return this.formatDate(row.createTime, "yyyy-MM-dd HH:mm:ss");
    },

    //table翻译 是否必备
    isMustFor: function(row, column) {
      return row.isMust == "1" ? "是" : row.isMust == "2" ? "否" : "否";
    },
    //table翻译 资料类别
    isFormerlyFor: function(row, column) {
      return row.isFormerly == "1" ? "是" : row.isFormerly == "2" ? "否" : "否";
    },

   initialization(v) {
      console.log("v......" + v);
      this.projId = v;
      let params = { projId: this.projId, mateType: "1" };
      console.log("params" + params);

      let self = this;
      this.$api
        .formPost(  "/api/biz/projMaterial/doGetList", params)
        .then(res => {
          if (res.retHead.code === "0000000") {
            self.tableData = res.retBody.list;
            for (const obj of this.tableData) {
              obj.isProvide = "1" == obj.isProvide ? true : false;
            }
          }
        });
    },
    init() {
      let params = { projId: this.projId, mateType: "1" };
      console.log("params" + params);

      let self = this;
      this.$api
        .formPost(  "/api/biz/projMaterial/doGetList", params)
        .then(res => {
          if (res.retHead.code === "0000000") {
            self.tableData = res.retBody.list;
            for (const obj of this.tableData) {
              obj.isProvide = "1" == obj.isProvide ? true : false;
            }
          }
        });
    },

    init2() {
      let params = { projId: this.projId, mateType: "2" };
      this.$api
        .formPost(  "/api/biz/projMaterial/doGetList", params)
        .then(res => {
          if (res.retHead.code === "0000000") {
            this.tableData2 = res.retBody.list;
            for (const obj of this.tableData2) {
              obj.isProvide = "1" == obj.isProvide ? true : false;
            }
          }
        });
    },
    getdata() {},
    /**
     * 保存
     */
    doSaveMateList(projectId) {
      this.projId = projectId;
      let params = [];
      params.projectId = projectId;
      params.serviceType = "1";

      let self = this;
      this.$api
        .formPost(  "/api/biz/projMaterial/doSaveList", params)
        .then(res => {
          if ((res.retHead.code = "0000000")) {
            self.init();
          } else {
          }
        });
    },
    /**
     * 切换
     */
    changeTab(a, b) {
      this.activeName = a.name;
      // 企业基础资料
      if ("tab1" == a.name) {
        this.init();
      } else {
        this.init2();
      }
    },
    /**
     * 提供
     */
    checkedIsUse(row) {
      let params = [];
      params.id = row.id;
      let flag = row.isProvide;
      params.isProvide = flag ? "1" : "0";

      row.isProvide = flag;
      let userStr = sessionStorage.getItem("user");
      let userObj = JSON.parse(userStr);
      params.checkUserId = userObj.id;
      params.checkUserName = userObj.realName;
      this.$api
        .formPost(  "/api/biz/projMaterial/doModById", params)
        .then(res => {
          if ((res.retHead.code = "0000000")) {
            this.$message({
              message: "提交成功！",
              type: "success"
            });
          } else {
            this.$message({
              message: res.retHead.message,
              type: "warning"
            });
          }
        });
    },
    //获取文档数
    getDocNum() {
      return this.gridData.length;
    },

    //打开弹出框
    handleClick(row) {
      this.formData = {
        id: row.id,
        projId: this.projId,
        uploDocNum: row.uploDocNum
      };
      if (this.activeName == "tab1") {
        this.dialogTableVisible = true;
      } else {
        this.dialogTableVisible1 = true;
      }
    },

    //取消方法
    quXiao() {
      //获取文档数
      var num = this.$refs.projMateUploadQyComponent.getUplaodNum();
      if (parseInt(this.formData.uploDocNum) != parseInt(num)) {
        let param = {
          id: this.formData.id,
          uploDocNum: num
        };
        this.$api
          .formPost(  "/api/biz/projMaterial/doModById", param)
          .then(res => {
            if ((res.retHead.code = "0000000")) {
              console.log(this.activeName);
              this.init();
              this.$message({
                message: "提交成功！",
                type: "success"
              });
            } else {
              this.$message({
                message: res.retHead.message,
                type: "warning"
              });
            }
          });
      }
    },

    //取消方法
    quXiao1() {
      //获取文档数
      var num = this.$refs.projMateUploadFdbComponent.getUplaodNum();
      if (parseInt(this.formData.uploDocNum) != parseInt(num)) {
        let param = {
          id: this.formData.id,
          uploDocNum: num
        };
        this.$api
          .formPost(  "/api/biz/projMaterial/doModById", param)
          .then(res => {
            if ((res.retHead.code = "0000000")) {
              this.init2();
              this.$message({
                message: "提交成功！",
                type: "success"
              });
            } else {
              this.$message({
                message: res.retHead.message,
                type: "warning"
              });
            }
          });
      }
    }
  }
};
</script>
<style lang='scss' scoped>
</style>